#include "EditorMaterialPageViewModel.h"

#include "Asset/EditorDefaultPackage.h"
#include "Material/Material.h"
#include "MaterialGraph/MaterialGraphModel.h"
#include "MaterialGraph/MaterialGraphViewModel.h"
#include "Framework/Editor.h"
#include "Theme/EditorTheme.h"

void REditorMaterialPageViewModel::BindModel(TSharedObjectPtr<REditorPageModel> InModel)
{
    Super::BindModel(InModel);
    MaterialModel=InModel;

    Icon =REditorDefaultPackage::Get()->GetIcon(U"MaterialIcon");
    UpdateIcon=REditorDefaultPackage::Get()->GetIcon(U"CodiconRefresh");
    {
        CClass* MaterialGraphViewModelClass=REditor::Get()->GetViewModelClass(
            MaterialModel->MaterialGraph->GetClass()
        );
        MaterialGraphViewModel=NewObject<RMaterialGraphViewModel>(MaterialGraphViewModelClass,this);
        MaterialGraphViewModel->BindModel(MaterialModel->MaterialGraph);
    }

}

TSharedObjectPtr<RTexture2D> REditorMaterialPageViewModel::GetIcon() const
{
    return Icon;
}

CString REditorMaterialPageViewModel::GetTitle() const
{
    return MaterialModel->Material->GetNodeName();
}

float REditorMaterialPageViewModel::GetOperationsWidth()
{
    return REditor::Get()->CurrentTheme->PageAreaButtonSize;
}

void REditorMaterialPageViewModel::UpdateMaterial()
{
    MaterialModel->UpdateMaterial();
}
